//
//  MFWDataCenter.m
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-24.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import "MFWDataCenter.h"

@implementation MFWDataCenter

- (id)init
{
    self = [super init];
    if (self)
    {
        _managedDataModels = [NSMutableDictionary dictionary];
    }
    return self;
}
- (MFWDataModel*)dataModelForCategory:(NSString*)category;
{
    NSAssert([category length] > 0, @"class name should not empty!!");
    
    
    MFWDataModel *dataModel = [_managedDataModels objectForKey:category];
    if (dataModel == nil)
    {
        dataModel = [[NSClassFromString(category) alloc] init];
        NSAssert(dataModel, @"Class '%@' not found!!", category);
        [_managedDataModels setObject:dataModel forKey:category];
    }
    
    return dataModel;
}

- (void)removeDataModelForCategory:(NSString*)category;
{
    [_managedDataModels removeObjectForKey:category];
}

- (NSArray*)allManagedDataCategories;
{
    return [_managedDataModels allKeys];
}

+ (MFWDataCenter *)sharedInstance;
{
    static MFWDataCenter* _sharedInstance = nil;
    if (_sharedInstance == nil)
	{
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _sharedInstance = [[MFWDataCenter alloc] init];
			
        });
	}
	
	return _sharedInstance;
}
@end
